home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HyperLib 1997 Winter - Disc 1
/
HYPERLIB-1997-Winter-CD1.ISO.7z
/
HYPERLIB-1997-Winter-CD1.ISO
/
オンラインウェア
/
UTIL
/
CD Playthrough 1.5.sit
/
CD Playthrough 1.5
/
Source
/
SoundOut.c
< prev
next >
Wrap
Text File
|
1996-11-20
|
3KB
|
106 lines
// CD Playthrough
// Version: 1.5 <October 3, 1994>
// (c) 1994 neg.active.productions, jwang@csua.berkeley.edu <James Wang>
// ftp://ftp.csua.berkeley.edu/pub/jwang/cool/cd-playthrough-15.hqx
// File: SoundOut.c
//
// Contains: Sound output sub-routines
//
// Written by: Gary, Anwyl, James Wang
//
// Description: Searches for the 'sdev' sound component, create an instance and
// references it for getting and setting the sound out rate option.
#include "main.h"
void open_sdev_component(ComponentInstance *compInst)
{
OSErr err;
Component comp;
ComponentDescription compDesc0, compDesc1;
Handle nameHandle;
// Allocate a handle for the name
nameHandle = NewHandle(256);
if (nameHandle == 0) stop_alert(MemFull);
HLock(nameHandle);
// Search all 'sdev' components for the "Built-In" sound driver
compDesc0.componentType = 'sdev';
compDesc0.componentSubType = 0;
compDesc0.componentManufacturer = 0;
compDesc0.componentFlagsMask = 0;
comp = 0;
while (1) {
comp = FindNextComponent(comp, &compDesc0);
if (comp == 0) stop_alert(soCompNotFound); // empty or exhausted component list
err = GetComponentInfo(comp, &compDesc1, nameHandle, 0, 0);
if (err != noErr) stop_alert(GetCompInfoFailed);
// nameHandle is a pascal string. See if it is "¥pBuilt-in"
if (EqualString("¥pBuilt-in", *((StringHandle)nameHandle), TRUE, FALSE))
break;
}
HUnlock(nameHandle);
DisposeHandle(nameHandle);
// Open the sound component
*compInst = OpenComponent(comp);
if (*compInst == 0) stop_alert(OpenCompFailed);
}
Boolean desired_rate_available(UnsignedFixed myWantRate)
{
int i;
OSErr err;
ComponentInstance compInst;
SRCInfoStruct srcInfo;
open_sdev_component(&compInst);
err = SoundComponentGetInfo(compInst, 0, siSampleRateAvailable, &srcInfo);
CloseComponent(compInst);
if (err != noErr) stop_alert(soGetCompInfoFailed);
if (srcInfo.count == 0) {
// The lower and upper bounds of a range was returned.
if ((*srcInfo.rates)[0] < myWantRate && (*srcInfo.rates)[1] > myWantRate)
return TRUE;
}
else {
// An array of available rates was returned
for (i=0; i<srcInfo.count; i++)
if ((*srcInfo.rates)[i] == myWantRate)
return TRUE;
}
return FALSE;
}
void get_sound_out(SoundSetting *mySnd)
{
OSErr err;
ComponentInstance compInst;
open_sdev_component(&compInst);
err = SoundComponentGetInfo(compInst, 0, siSampleRate, &(mySnd->soCurrRate));
CloseComponent(compInst);
if (err != noErr) stop_alert(soGetCompInfoFailed);
}
void set_sound_out(SoundSetting *mySnd)
{
OSErr err;
ComponentInstance compInst;
open_sdev_component(&compInst);
err = SoundComponentSetInfo(compInst, 0, siSampleRate, (void *)mySnd->soWantRate);
CloseComponent(compInst);
if (err != noErr) stop_alert(soSetCompInfoFailed);
}